﻿using NLog;
using System.Data.Entity;

namespace IOA.MES.DataAccess.Entity
{
    public partial class MESContext : DbContext
    {
        private readonly string nameOrConnectionString;
        private readonly Logger logger = LogManager.GetCurrentClassLogger();

        public MESContext(string nameOrConnectionString)
            : base("name=" + nameOrConnectionString)
        {
            this.nameOrConnectionString = nameOrConnectionString;
            this.Configuration.UseDatabaseNullSemantics = true;
            Database.Log = x =>
            {
                System.Diagnostics.Debug.WriteLine(x);
                logger.Debug(x.ToString());
            };
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            Database.SetInitializer<MESContext>(null);
            //标片
            modelBuilder.Entity<StandardPiece>().Property(x => x.Pmax).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.PmaxToleranceDown).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.PmaxToleranceUp).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.Voc).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.VocToleranceDown).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.VocToleranceUp).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.Isc).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.IscToleranceDown).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.IscToleranceUp).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.Vmp).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.VmpToleranceDown).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.VmpToleranceUp).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.Imp).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.ImpToleranceDown).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.ImpToleranceUp).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.FF).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.FFToleranceDown).HasPrecision(18, 4);
            modelBuilder.Entity<StandardPiece>().Property(x => x.FFToleranceUp).HasPrecision(18, 4);

            //IV数据
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.IVPowerLevel).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Temp).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.EnvTemp).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Voc).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Isc).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Pmax).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Vm).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Im).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.FF).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.NCell).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Ress).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Ressh).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.NModule).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.ModEff).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.TMod).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Insol).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.SunRef).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Irev).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Ivld).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Vld).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.StdIsc).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Pvld).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Area).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.Jsc).HasPrecision(18, 4);
            modelBuilder.Entity<ProductViaSiteIVData>().Property(x => x.RCTemp).HasPrecision(18, 4);

            //组件
            modelBuilder.Entity<Component>().Property(x => x.CellArea).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.CellEfficiency).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.ConversionEfficiency).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.SinglePiecePower).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.TheoreticalPower).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Isc).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Voc).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Vm).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Im).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.FF).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Pmax).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Temp).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Ress).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.Ressh).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.ModEff).HasPrecision(18, 4);
            modelBuilder.Entity<Component>().Property(x => x.SunRef).HasPrecision(18, 4);

            //电流档
            modelBuilder.Entity<BinningCurrent>().Property(x => x.CurrentMin).HasPrecision(18, 4);
            modelBuilder.Entity<BinningCurrent>().Property(x => x.CurrentMax).HasPrecision(18, 4);

            //功率档
            modelBuilder.Entity<BinningPower>().Property(x => x.Power).HasPrecision(18, 4);
            modelBuilder.Entity<BinningPower>().Property(x => x.PowerMin).HasPrecision(18, 4);
            modelBuilder.Entity<BinningPower>().Property(x => x.PowerMax).HasPrecision(18, 4);
            modelBuilder.Entity<WorkOrderBinningSchema>().Property(x => x.BinningPower).HasPrecision(18, 2);

            //BOM
            modelBuilder.Entity<WorkOrderBom>().Property(x => x.Count).HasPrecision(18, 4);
            modelBuilder.Entity<WorkOrderBom>().Property(x => x.SingleCount).HasPrecision(18, 6);

            //WMS入库任务
            modelBuilder.Entity<WmsInboundTaskItem>().Property(x => x.Im).HasPrecision(18, 6);
            modelBuilder.Entity<WmsInboundTaskItem>().Property(x => x.Vm).HasPrecision(18, 6);
            modelBuilder.Entity<WmsInboundTaskItem>().Property(x => x.Isc).HasPrecision(18, 6);
            modelBuilder.Entity<WmsInboundTaskItem>().Property(x => x.Voc).HasPrecision(18, 6);
            modelBuilder.Entity<WmsInboundTaskItem>().Property(x => x.Pmax).HasPrecision(18, 6);

            //线边库存
            modelBuilder.Entity<LineStorage>().Property(x => x.Quantity).HasPrecision(18, 6);
            modelBuilder.Entity<LineStorage>().Property(x => x.OriginQuantity).HasPrecision(18, 6);
            modelBuilder.Entity<ProductViaSiteMaterial>().Property(x => x.Quantity).HasPrecision(18, 2);
            modelBuilder.Entity<AllocateProduct>().Property(x => x.Quantity).HasPrecision(18, 4);
            modelBuilder.Entity<AllocateProduct>().Property(x => x.ReceiveQuantity).HasPrecision(18, 4);
            modelBuilder.Entity<LineMaterialBillItem>().Property(x => x.Quantity).HasPrecision(18, 6);
            base.OnModelCreating(modelBuilder);
        }
    }
}
